﻿using Fluid;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Asion.VSIX.Code.Create.Core
{
    /// <summary>
    /// razor template utils
    /// </summary>
    public class TemplateFactory
    {

        /*
            --relation document
            https://github.com/sebastienros/fluid/tree/main
            https://www.coderbusy.com/liquid/tags/iteration/


            --如果新增模型需要使用才可以正常的渲染数据
              context.Options.MemberAccessStrategy.Register<ParameterGenerative>();
         */

        private FluidParser parser = null;

        /// <summary>
        /// 初始化 模版
        /// </summary>
        /// <param name="filePath"></param>
        public  TemplateFactory()
        {
            parser = new FluidParser(); 

        }

     


    


        /// <summary>
        /// 渲染数据
        ///
        /// </summary>
        /// <param name="data"></param>
        public string Render(string templdate, TemplateContext context)
        {

            if (parser.TryParse(templdate, out var template, out var error))
            {
               return template.Render(context);
            }
            else {
                throw new Exception("模版数据异常");
            } 
        }
    }
}
